package com.sn.springboot_netty.utils;

import org.apache.commons.lang3.StringUtils;

import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author fyy
 * @Description
 * @Date 2020/5/29 13:15
 */
public class DateUtil {

    public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_TIME_STRING_PATTERN = "yyyyMMddHHmmssSSS";
    public static final String MINUTE_PATTERN = "yyyy-MM-dd HH:mm";
    public static final String HOUR_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_PATTERN = "yyyy-MM-dd";
    public static final String MONTH_PATTERN = "yyyy-MM";
    public static final String YEAR_PATTERN = "yyyy";
    public static final String MINUTE_ONLY_PATTERN = "mm";
    public static final String HOUR_ONLY_PATTERN = "HH";

    /**
     * @Author fyy
     * @Description 时间格式化
     * @param date 时间
     * @param pattern 格式化类型
     * @Date 2020/5/29 13:20
     */
    public static synchronized String dateFormat(Date date, String pattern) throws ParseException {
        if(StringUtils.isBlank(pattern)){
           pattern = DateUtil.DATE_TIME_STRING_PATTERN;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }






}
